var a = require("../../utils/config.js");

Page({
    data: {
        timer: null,
        isCanSend: !0,
        count: 60,
        idCard: "",
        userName: "",
        mobile: "",
        code: "",
        password: "",
        againPassword: ""
    },
    onLoad: function(a) {},
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    getIdCard: function(a) {
        this.setData({
            idCard: a.detail.value
        });
    },
    getUserName: function(a) {
        this.setData({
            userName: a.detail.value
        });
    },
    getMobile: function(a) {
        this.setData({
            mobile: a.detail.value
        });
    },
    getCode: function(a) {
        this.setData({
            code: a.detail.value
        });
    },
    getPassword: function(a) {
        this.setData({
            password: a.detail.value
        });
    },
    getAgainPassword: function(a) {
        this.setData({
            againPassword: a.detail.value
        });
    },
    sendCode: function() {
        var t = this;
        t.data.idCard ? t.data.mobile ? (wx.showLoading({
            mask: !0
        }), wx.request({
            url: a.urlList.API_USER_SEND_SMS_FOR_REGIST,
            method: "POST",
            header: {
                contentType: "application/json"
            },
            data: {
                idCard: t.data.idCard,
                mobile: t.data.mobile
            },
            success: function(a) {
                wx.hideLoading(), 200 == a.data.status ? t.countDown() : wx.showToast({
                    title: a.data.message,
                    icon: "none"
                });
            }
        })) : wx.showToast({
            title: "请输入手机号码",
            icon: "none"
        }) : wx.showToast({
            title: "请输入身份证号码",
            icon: "none"
        });
    },
    countDown: function() {
        var a = this, t = a.data.count;
        t >= 1 ? (t--, a.data.timer = setTimeout(function() {
            a.setData({
                count: t,
                isCanSend: !1
            }), a.countDown();
        }, 1e3)) : (clearTimeout(a.data.timer), a.setData({
            timer: null,
            isCanSend: !0,
            count: 60
        }));
    },
    regist: function() {
        var t = this;
        t.data.idCard ? t.data.mobile ? t.data.code ? t.data.userName ? t.data.password ? t.data.againPassword ? t.data.password == t.data.againPassword ? (wx.showLoading({
            mask: !0
        }), wx.request({
            url: a.urlList.API_USER_REGIST,
            method: "POST",
            header: {
                contentType: "application/json"
            },
            data: {
                mobile: t.data.mobile,
                userName: t.data.userName,
                idCard: t.data.idCard,
                password: t.data.password,
                code: t.data.code
            },
            success: function(a) {
                wx.hideLoading(), 200 == a.data.status ? (wx.showToast({
                    title: "注册成功"
                }), wx.navigateBack()) : wx.showToast({
                    title: a.data.message,
                    icon: "none"
                });
            }
        })) : wx.showToast({
            title: "两次密码输入不一致",
            icon: "none"
        }) : wx.showToast({
            title: "请输入确认密码",
            icon: "none"
        }) : wx.showToast({
            title: "请输入登录密码",
            icon: "none"
        }) : wx.showToast({
            title: "请输入真实姓名",
            icon: "none"
        }) : wx.showToast({
            title: "请输入验证码",
            icon: "none"
        }) : wx.showToast({
            title: "请输入手机号码",
            icon: "none"
        }) : wx.showToast({
            title: "请输入身份证号",
            icon: "none"
        });
    }
});